package com.fwx.chatroom.controller;

import com.fwx.chatroom.mapper.MessageMapper;
import com.fwx.chatroom.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    //查询历史消息
    @GetMapping("/message")
    public Object getMessage(Integer sessionId) {
      List<Message> messages = messageMapper.getMessageBySessionId(sessionId);
      //查询结果逆序 得到的是按照时间降序排序 实际需要最新消息在下面，按照升序排序
      Collections.reverse(messages);
      return messages;
    }
}
